<?php 
if(isset($onlineuser) && !empty($onlineuser))
{
	$display="display:block";
}
else
{
	$display="display:none";
}
?>
<link href="<?php echo base_url('chat/css/chat.css');  ?>" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo base_url('chat/js/chat.js'); ?>"></script>		
<h2 class="profile-frnd-heading">Friends</h2>
<ul class="nav nav-sidebar left-sidebar-profile-frnd-menu" id="onlineuser">
	
	<?php foreach($onlineuser as $online){?>
	<li>
		<a href="<?php if($online['online']){?>javascript:void(0)<?}else{?><?php echo base_url('users/profile/'.$online['userid']);?><?}?>" <?php if($online['online']){?> onclick="javascript:chatWith('<?=$online['firstname']?>','<?=$online['userid']?>')" <?}?>>		
			<img src="<?php echo base_url(); ?>assets/uploads/.thumbs/images/zap/<?php echo $online['photo'] == '' ? DEFAULT_IMG : $online['photo'] ; ?>" class="img-responsive frnd-img" width="32" height="32">
					
			<span class="frnd-name"><?=$online['firstname']?></span>
			<?php if($online['online']){?>
			<img src="<?php echo base_url(); ?>assets/front/images/online-symbol.png" alt="Online" class="img-responsive online-btn">
			<?}?>
		</a>
	</li>
	<?}?>
	
	<li>
		<a href="#" class="more-link">More</a>
	</li>
</ul>

<script>

$(document).ready(function(){
	/*$.ajax({
		url: '<?php echo base_url()?>ajax/onlineuser',
		dataType: 'json',			
		success: function(json) {
			
			html='';
			if(jQuery.isEmptyObject( json ))
			{
				$('#showonline').hide();
			}
			else
			{
				$('#showonline').show();
				$.each(json.users, function(i, v) {
					html+='<li><a href="javascript:void(0)" onclick="javascript:chatWith(\''+v.firstname+'\')"><img src="<?php echo base_url();?>assets/cms/img/ba.jpg" class="images img-rounded"></a><br /><span class="name">'+v.firstname+'</span><span><img src="<?php echo base_url();?>assets/cms/img/active.png" class="imageactivebtn"></span></li>';
				});
			}
			
			$('#onlineuser').html(html);
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});*/
	setInterval(function(){
	$.ajax({
		url: '<?php echo base_url()?>ajax/onlineuser',
		dataType: 'json',			
		success: function(json) {
			html='';
			if(jQuery.isEmptyObject( json ))
			{
				$('#showonline').hide();
			}
			else
			{
				$('#showonline').show();
				$.each(json.users, function(i, v) {
					if(v.photo=="")
					{
						photo='<?=DEFAULT_IMG?>';
					}
					else
					{
						photo=v.photo;
					}
					if(v.online)
					{
						
					}
					html+='<li>';
					if(v.online)
					html+='<a href="javascript:void(0)"';
					else
					html+='<a href="<?php echo base_url('users/profile');?>/'+v.userid+'"';
					if(v.online)
					html+='onclick="javascript:chatWith(\''+v.firstname+'\',\''+v.userid+'\')"';
					html+='>';
					html+='<img src="<?php echo base_url(); ?>assets/uploads/.thumbs/images/zap/'+photo+'" class="img-responsive frnd-img" width="32" height="32">';
					html+='<span class="frnd-name">'+v.firstname+'</span>';
					if(v.online)
					html+='<img src="<?php echo base_url(); ?>assets/front/images/online-symbol.png" class="img-responsive online-btn">';
					html+='</li></a>';
				});
			}
			
			
			$('#onlineuser').html(html);
		},
		error: function(xhr, ajaxOptions, thrownError) {
			//alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
   },10000);
		
});
</script>